package com.godme.string;

public class RK {

    private static int scale = 26;



    public static int numberHash(String a, int lastHash, int start, int end, int scale){
        if(start < end){
            return numberHash(a, lastHash + a.charAt(start) * scale, start + 1, end, scale * scale);
        }
        return lastHash;
    }

    public static int find(String mainString, String matchString){
        int matchLength = matchString.length();
        int maxLength = mainString.length() - matchLength;
        int matchHash = numberHash(matchString, 0, 0, matchLength, scale);
        for(int i=0; i<=maxLength; i++){
            if(matchHash == numberHash(mainString, 0, i, i+matchLength, scale)){
                return i;
            }
        }
        return -1;
    }

    public static void main(String[] args) {
        System.err.println(find("aaabc", "bc"));
    }
}
